import java.util.*;


public class Leetcode908 {

    public int smallestRangeI(int[] nums, int k) {
        if (nums.length == 1 || k >= 5000) {
            return 0;
        }

        int min = 10000;
        int max = 0;
        for (int num : nums) {
            if (max < num) {
                max = num;
            }

            if (min > num) {
                min = num;
            }
        }

        return Math.max(0, max - min - 2 * k);
    }
}
